﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Clipper.Model.DetectionModel
{
    public class CupStrip
    {
       // ObservableCollection<Cup> cups = 
        public CupStrip()
        {
            
        }

        public enum ReactionStripStatusEnum
        {
            /// <summary>
            /// 反应条的运行状态，加载状态位load（有杯子的时候），杯子加满置为full，杯子反应完成或者刚启动时杯子为unload
            /// </summary>
            LOAD = 0,
            FULL = 1,
            UNLOAD = 2            

        }

        private ReaderWriterLockSlim rwLock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);

        private ObservableCollection<Cup> cups = new ObservableCollection<Cup>();
        public ObservableCollection<Cup> Cups
        {
            get
            {
                return cups;
            }

            set
            {
                cups = value;
            }
        }



        private ReactionStripStatusEnum status = ReactionStripStatusEnum.UNLOAD;

        public ReactionStripStatusEnum getStatus()
        {
            rwLock.EnterReadLock();
            try
            {
                return this.status;
            }
            finally
            {
                rwLock.ExitReadLock();
            }
        }

        public void setStatus(ReactionStripStatusEnum state)
        {
            rwLock.EnterWriteLock();
            try
            {
                this.status = state;
            }
            finally
            {
                rwLock.ExitWriteLock();
            }
            
        }

        /// <summary>
        /// 杯条的孔位
        /// </summary>
        private int stripSeat;
        public int StripSeat
        {
            get
            {
                return stripSeat;
            }

            set
            {
                stripSeat = value;
            }
        }
        public void init()
        {
            status = ReactionStripStatusEnum.LOAD;
           
            for(int i = 0; i < Cups.Count; i++)
            {
                Cups[i].setStatus(Cup.CupHoleStatusEnum.EMPTY);
            }
        }


        public void setStatus(object lOAD)
        {
            throw new NotImplementedException();
        }
    }
}
